package com.hlkj.warboot.configurer.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

/**
 * @Description: TODO 继承org.springframework.security.core.userdetails.User，拓展SpringSecurity下登陆用户的额外信息
 * @Author: 李星
 * @Date: 2019/10/11 10:12
 */
public class SecurityUser extends User {
    // TODO 以下的所有字段在用户的授权信息中都可以读到，如果想拓展其它的字段，在这里添加即可
    private String id; // 编号
    private int grade; // 用户等级（用户等级（1:超级管理员,2:省级管理员,3:地市用户,4:区县管理员））
    private String cover; // 用户头像
    private String phone; // 手机号码（同一个手机号码可以被多个账号绑定）
    private String email; // 邮箱（同一个手机号码可以被多个账号绑定）

    /*
     * @Description TODO 场景1
     * @Author 李星
     * @Date 2019/9/30 22:34
     * @Param [id, username 用户账户account, password, grade, cover, phone, email, authorities]
     * @return
     */
    public SecurityUser(
            String id, String username, String password, int grade, String cover, String phone, String email,
            Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
        this.id = id;
        this.grade = grade;
        this.cover = cover;
        this.phone = phone;
        this.email = email;
    }

    /*
     * @Description TODO 场景2
     * @Author 李星
     * @Date 2019/9/30 22:34
     * @Param [id, username 用户账户account, password, grade, cover, phone, email, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities]
     * @return
     */
    public SecurityUser(
            String id, String username, String password, int grade, String cover, String phone, String email,
            boolean enabled,
            boolean accountNonExpired,
            boolean credentialsNonExpired,
            boolean accountNonLocked,
            Collection<? extends GrantedAuthority> authorities
    ) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.id = id;
        this.grade = grade;
        this.cover = cover;
        this.phone = phone;
        this.email = email;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }
}
